home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / SYS_TOOL / MULTI020 / NCONV.PAS < prev    next >
Pascal/Delphi Source File  |  1993-09-01  |  2KB  |  133 lines

  1. unit NConv;
  2. { FAST hex conversion routines }
  3. interface
  4.  
  5. function Byte2FHex(b : byte) : string;  { Byte2FHex(15) = '0F' }
  6. function Byte2Hex(b : byte) : string;   { Byte2Hex(15) = 'F' }
  7. function Word2FHex(w : word) : string;  { Word2FHex(15) = '000F' }
  8. function Word2Hex(w : word) : string;   { Word2Hex(15) = 'F' }
  9.  
  10. implementation
  11.  
  12. function Byte2FHex(b : byte) : string; assembler;
  13. asm
  14.   les di,[@result]
  15.   mov dl,[b]
  16.   xor dh,dh
  17.   mov al,2
  18.   stosb
  19.   mov ch,2
  20. @@1:
  21.   mov cl,4
  22.   rol dx,cl
  23.   mov al,dh
  24.   and al,0Fh
  25.   add al,30h
  26.   cmp al,3Ah
  27.   jb @@2
  28.   add al,7
  29. @@2:
  30.   stosb
  31.   dec ch
  32.   jnz @@1
  33. end;
  34.  
  35. function Byte2Hex(b:byte) : string; assembler;
  36. asm
  37.   les di,[@result]
  38.   mov dl,[b]
  39.   mov al,0
  40.   mov dh,al
  41.   xor bx,bx
  42.   stosb
  43.   mov ch,2
  44.   mov si,di
  45. @@1:
  46.   mov cl,4
  47.   rol dx,cl
  48.   mov al,dh
  49.   and al,0Fh
  50.   add al,30h
  51.   cmp al,3Ah
  52.   jb @@2
  53.   add al,7
  54. @@2:
  55.   cmp al,'0'
  56.   je @@3
  57.   stosb
  58.   inc bl
  59. @@3:
  60.   dec ch
  61.   jnz @@1
  62.   cmp bl,0
  63.   jne @@4
  64.   mov al,'0'
  65.   stosb
  66.   inc bl
  67. @@4:
  68.   les di,[@result]
  69.   mov al,bl
  70.   stosb
  71. end;
  72.  
  73. function Word2FHex(w : word) : string; assembler;
  74. asm
  75.   les di,[@result]
  76.   mov dx,[w]
  77.   mov al,4
  78.   stosb
  79.   mov ch,4
  80. @@1:
  81.   mov cl,4
  82.   rol dx,cl
  83.   mov al,dl
  84.   and al,0Fh
  85.   add al,30h
  86.   cmp al,3Ah
  87.   jb @@2
  88.   add al,7
  89. @@2:
  90.   stosb
  91.   dec ch
  92.   jnz @@1
  93. end;
  94.  
  95. function Word2Hex(w:word) : string; assembler;
  96. asm
  97.   les di,[@result]
  98.   mov dx,[w]
  99.   mov al,0
  100.   xor bx,bx
  101.   stosb
  102.   mov ch,4
  103.   mov si,di
  104. @@1:
  105.   mov cl,4
  106.   rol dx,cl
  107.   mov al,dl
  108.   and al,0Fh
  109.   add al,30h
  110.   cmp al,3Ah
  111.   jb @@2
  112.   add al,7
  113. @@2:
  114.   cmp al,'0'
  115.   je @@3
  116.   stosb
  117.   inc bl
  118. @@3:
  119.   dec ch
  120.   jnz @@1
  121.   cmp bl,0
  122.   jne @@4
  123.   mov al,'0'
  124.   stosb
  125.   inc bl
  126. @@4:
  127.   les di,[@result]
  128.   mov al,bl
  129.   stosb
  130. end;
  131.  
  132. end.
  133.